<template>
    <!-- 抬头 -->
    <PageTitle :classify="classify" />

    <!-- 医师信息 -->
    <div class="doctor-info">
        <img src="@/assets/images/aboutDoctorPage/touxiang.png">
        <div class="doctor-info-content">
            <span class="docName">{{ doctor.name }}</span>
            <span class="docTitle">{{ doctor.title }}</span>
            <img src="@/assets/images/aboutDoctorPage/onlineAsk.png" class="ask-btn"
                @click="onlineAsk(doctor.id, doctor.name)">
            <br>
            <span class="docDepartment">{{ doctor.department }}</span>
            <span class="docHospital">{{ doctor.hospital }}</span>
        </div>
    </div>

    <!-- 工作信息 -->
    <div class="doctor-work">
        <ul class="work-list">
            <li>
                <span>从业年限</span>
                <p>20</p>
            </li>
            <li>
                <span>好评率</span>
                <p>{{doctor.evaluate}}%</p>
            </li>
            <li>
                <span>回答次数</span>
                <p>{{ doctor.peopleServed }}</p>
            </li>
        </ul>
        <div class="work-down">
            <span>三甲医院</span>
            <img src="@/assets/images/aboutDoctorPage/xunzhang.png">
            <span>医师认证</span>
            <img src="@/assets/images/aboutDoctorPage/xunzhang.png">
        </div>
    </div>

    <!-- 医师简历 -->
    <div class="doctor-resume">
        <img src="@/assets/images/aboutDoctorPage/yuanhuan.png">
        
        <div class="doctor-resume-title">
            <div class="title"><span>{{ doctor?.jibing?.jibing1 }}</span></div>
            <div class="title"><span>{{ doctor?.jibing?.jibing2 }}</span></div>
        </div>
        <div class="doctor-resume-content">
            <p>擅长：{{ doctor.intro }}</p>
        </div>
    </div>
    <!-- 登录确认弹窗 -->
    <div v-if="showLoginConfirm" class="login-confirm-overlay" @click="closeLoginConfirm">
                <div class="login-confirm-dialog" @click.stop>
                    <div class="login-confirm-content">
                        <div class="login-confirm-title">您当前未登录</div>
                        <div class="login-confirm-text">登录后才能使用该功能</div>
                        <div class="login-confirm-buttons">
                            <button class="login-btn" @click="goToLogin">去登录</button>
                            <button class="cancel-btn" @click="closeLoginConfirm">再看看</button>
                        </div>
                    </div>
                </div>
            </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import PageTitle from '@/components/pageTitle/pageTitle.vue';
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();


const route = useRoute();
const router = useRouter();
const doctorId = ref(route.query.docId);
// 从URL的查询参数中获取医生信息  
const doctorQuery = route.query.doctor;
const doctor = doctorQuery ? JSON.parse(decodeURIComponent(doctorQuery)) : null;

const classify = `宠物科-${doctor.name}-医师详情`;
const showLoginConfirm = ref(false);
// 关闭登录确认弹窗
const closeLoginConfirm = () => {
    showLoginConfirm.value = false;
};

// 去登录
const goToLogin = () => {
    router.push({path:"/login"});
    closeLoginConfirm();
};


const onlineAsk = (id, name) => {
    if(!userStore.token || !userStore.userInfo || !userStore.userInfo.id){
        showLoginConfirm.value = true;
        return;
    }     
    router.push({
        path: '/onlineAsk',
        query: {
            docId: id,
            name: name,
        }
    })
}





</script>

<style lang="less" scoped>
.doctor-info {
    width: 100%;
    height: 100px;
    opacity: 1;
    border-radius: 0 22.5px 0 22.5px;
    background: rgba(192, 223, 124, 0.75);
    position: relative;

    img {
        position: absolute;
        width: 75px;
        top: 12.5px;
        left: 10px;
    }

    .doctor-info-content {
        position: absolute;
        margin-top: 25.5px;
        margin-left: 97px;


        .docName {
            /** 文本1 */
            font-size: 16px;
            font-weight: 900;
        }

        .docTitle {
            /** 文本1 */
            font-size: 12px;
            font-weight: 500;
            margin-left: 18.5px;
        }

        .ask-btn {
            width: 120px;
            height: 35px;
            margin-left: 135px;
            position: absolute;
            top: -10px;
        }

        .docDepartment {
            /** 文本1 */
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0px;
            line-height: 31.61px;
        }

        .docHospital {
            /** 文本2 */
            margin-left: 15px;
            font-size: 11px;
            font-weight: 500;
            letter-spacing: 0px;
            line-height: 31.61px;
            color: rgba(56, 56, 56, 1);
        }
    }
}

.doctor-work {
    width: 100%;
    height: 100px;
    margin-top: 1.5px;
    opacity: 1;
    border-radius: 22.5px 0px 0px 0px;
    background: rgba(192, 223, 124, 0.25);

    .work-list {
        display: flex;
        justify-content: space-between;
        align-items: center;
        list-style: none;
        padding: 0;
        margin: 0;

        li {
            flex: 1;
            text-align: center;
            padding: 10px;

            span {
                display: block;
                font-size: 14px;
                font-weight: bold;
            }

            p {
                display: block;
                /** 文本1 */
                font-size: 19px;
                font-weight: 900;
                color: rgba(75, 107, 6, 1);
            }
        }
    }

    .work-down {
        display: flex;

        img {
            width: 24px;
            margin-left: 5px;
        }

        span {
            margin-left: 35px;
        }
    }
}

.doctor-resume {
    width: 100%;
    height: 419.5px;
    margin-top: 6px;
    opacity: 1;
    border-radius: 45px 0px, 0px, 0px;
    background: rgba(192, 223, 124, 0.1);
    position: relative;

    img {
        position: absolute;
        top: 8px;
        left: 31px;
        width: 86.5px;
        height: 30px;
    }

    .doctor-resume-title {
        position: absolute;
        top: 55px;
        left: 35px;
        display: flex;

        .title {
            background: rgba(204, 204, 204, 0.45);
            height: 24px;
            border-radius: 25px;
            margin-right: 5px;
            display: flex;
            align-items: center;
            justify-content: center;

            span {
                font-size: 11px;
                // 设置一个自定义的宽度，让文字宽度自适应，不局限于三个字的疾病
                width: 100%;
                padding-left: 23.5px;
                padding-right: 23.5px;
                align-items: center;
                text-align: center;
            }
        }
    }

    .doctor-resume-content {
        position: absolute;
        top: 96px;
        left: 42px;

        p {
            /** 文本1 */
            font-size: 11px;
            font-weight: 500;
            width: 288px;
            letter-spacing: 0px;
            line-height: 31.61px;
            color: rgba(56, 56, 56, 1);
        }
    }
}
.login-confirm-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 2000;
    }

    .login-confirm-dialog {
        width: 80%;
        max-width: 300px;
        background-color: white;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .login-confirm-content {
        padding: 20px;
    }

    .login-confirm-title {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 10px;
        text-align: center;
        color: #333;
    }

    .login-confirm-text {
        font-size: 14px;
        margin-bottom: 20px;
        text-align: center;
        color: #666;
    }

    .login-confirm-buttons {
        display: flex;
        justify-content: space-between;
    }

    .login-btn {
        flex: 1;
        margin-right: 10px;
        padding: 10px 0;
        background-color: #c6caa4;
        color: white;
        border: none;
        border-radius: 6px;
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
    }

    .cancel-btn {
        flex: 1;
        padding: 10px 0;
        background-color: #f5f5f5;
        color: #666;
        border: none;
        border-radius: 6px;
        font-size: 14px;
        cursor: pointer;
    }
</style>